package com.bootcamp.sb1126yml.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.bootcamp.sb1126yml.properties.DataSourcePropertiesC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @program: spring-boot
 * @description:
 * @author: Keyu Li
 * @create: 2021-11-26 11:08
 **/

/*
* 进一步解耦，提取成员变量，使用专门的 参数类 接收
* */

@Configuration
public class DataSourceConfiguration3 {

    @Autowired
    DataSourcePropertiesC properties;

    @Bean("dataSource3")
    public DataSource dataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        return dataSource;
    }
}
